package com.yyk.springservicetwo.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ljp
 * @CLASSNAME RedissonConfig
 * @date 2021/2/3 11:02
 * @description：
 */
@Configuration
public class RedissonConfig {

    @Autowired
    private RedissonProperties redissonProperties;

    @Bean
    public RedissonClient getRedisson() {
        Config config = new Config();
        //单机模式  依次设置redis地址和密码
        config.useSingleServer().
                setAddress("redis://" + redissonProperties.getHost() + ":" + redissonProperties.getPort()).
                setPassword(redissonProperties.getPassword());
        config.setCodec(new StringCodec());
        return Redisson.create(config);
    }

}
